package kr.co.graviti.common.util;

/** 암호화,복화화 가능 
 * @author ljb
 * String aa = new CaesarMain().Encrypt('암호화 대상 ',80);
	System.out.println(aa);
	aa = new CaesarMain().Decrypt(aa,80);
	System.out.println(aa);
 *
 */
public class CaesarMain{
	public CaesarMain() {}
	 
    private int defaultKey = -3;
 
    public String Encrypt(String s) {
        return Encrypt(s, defaultKey);
    }
 
    public String Decrypt(String s) {
        return Decrypt(s, defaultKey);
    }
   
    public String Encrypt(String s, int key) {
        String rtn = "";
        try{
            byte[] cc = s.getBytes();
            for(int i=0; i< cc.length; i++){
                cc[i] = (byte)(cc[i]-key);
            }
            rtn = new String(cc);
        }catch(Exception e){
            e.printStackTrace();
        }
        return rtn;
    }
 
    public String Decrypt(String s, int key){
                                   String rtn = "";
        try{
            byte[] cc = s.getBytes();
            for(int i=0; i< cc.length; i++){
                cc[i] = (byte)(cc[i]+key);
            }
            rtn = new String(cc);
        }catch(Exception e){
            e.printStackTrace();
        }
        return rtn;
    }
}
